package com.marchsoft.service.impl;

import com.marchsoft.common.enums.ExceptionEnum;
import com.marchsoft.common.exception.CommonException;
import com.marchsoft.common.mapper.CommentMapper;
import com.marchsoft.dao.CommMapper;
import com.marchsoft.domain.Comm;
import com.marchsoft.service.ICommService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * class description：
 * author：rsw
 * Date: 2019/11/17
 * Time: 10:51
 **/
@Service
public class CommServiceImpl implements ICommService {

    @Resource
    private CommMapper commMapper;


    /**
     * 查找所有的会议内容
     * @return 所有的会议内容集合
     */
    @Override
    public List<Comm> findAll() {
        //如果集合为空，则抛出异常
        if (CollectionUtils.isEmpty(commMapper.selectAll())){
            throw new CommonException(ExceptionEnum.COMM_NOT_FOUND);
        }
        //返回查询结果
        return commMapper.selectAll();
    }

    /**
     * 根据会议记录id查询一条会议记录
     * @param cid 会议记录id
     * @return 一条会议记录
     */
    @Override
    public Comm queryCommByCid(Integer cid) {
        if (commMapper.selectByPrimaryKey(cid)==null){
            throw new CommonException(ExceptionEnum.COMM_NOT_FOUND);
        }
        return commMapper.selectByPrimaryKey(cid);
    }

    /**
     * 插入会议内容到数据库
     * @param comm 与数据库表对应的javabean
     * @return true&fasle
     */
    @Override
    public Boolean insertComm(Comm comm) {
        int count=commMapper.insertSelective(comm);
        if (count<0){
            throw new CommonException(ExceptionEnum.INSERT_COMM_ERROR);
        }
        return count>=0;
    }


}

